{% extends "shared/layout.volt" %}
{% block content %}
    <h1 class="page-header">支付账号信息</h1>
    <div class="form-box form-app-box">
        <form class="form-horizontal">
            <input type="hidden" name="app_id" value="">
            <div class="form-title-box">
                <h3 class="view-title">基础信息</h3>
                <button type="button" class="btn btn-default btn-sm pull-right" onclick="window.location=window.document.referrer;" style="margin-left: 5px;">返回</button>
                <a href="{{ url('home/delete') }}?pay_id={{ Model.pay_id }}" class="btn btn-danger btn-sm pull-right" style="margin-left: 5px;">删除</a>
                <button type="button" data-toggle="modal" data-target="#payInfoEditModal" class="btn btn-primary-light btn-sm pull-right" style="margin-left: 5px;">修改</button>
            </div>
            <table class="table-detail">
                <tbody>
                <tr>
                    <td>支付名称</td>
                    <td id="pay_name_text">{{ Model.pay_name }}</td>
                </tr>
                <tr>
                    <td>商户编码</td>
                    <td>{{ Model.pay_id }}</td>
                </tr>
                <tr>
                    <td>支付账号</td>
                    <td>{{ Model.pay_account }}</td>
                </tr>
                <tr>
                    <td>支付平台</td>
                    <td>{{  convert_pay_name(Model.pay_platform) }}</td>
                </tr>
                <tr>
                    <td>加密类型</td>
                    <td>{{ Model.sign_type }}</td>
                </tr>
                <tr>
                    <td>网关类型</td>
                    <td>{{ convert_pay_gateway(Model.gateway) }}</td>
                </tr>
                <tr>
                    <td>启用状态</td>
                    <td id="pay_status_text">{{ Model.pay_status == 'y' ? '启用' : '禁用' }}</td>
                </tr>
                <tr>
                    <td>添加时间</td>
                    <td>{{ Model.create_time }}</td>
                </tr>
                <tr>
                    <td>支付简介</td>
                    <td id="remark_text">{{ Model.remark=='' ? '无' :  Model.remark }}</td>
                </tr>
                </tbody>
            </table>


            <div class="form-title-box">
                <h3 class="view-title">专有信息</h3>
            </div>

            <table class="table-detail" style="margin-bottom: 50px;">
                <tbody>
                {% if Model.pay_platform == 'wxpay' or  Model.pay_platform == 'wxpay_global' %}
                    <tr>
                        <td>商户公众号APPID</td>
                        <td>{{ Model.pay_config['app_id'] }}</td>
                    </tr>
                    <tr>
                        <td>商户号</td>
                        <td>{{ Model.pay_config['mch_id'] }}</td>
                    </tr>
                    <tr>
                        <td><?php echo $this->config->payment_platform_list->{$Model->pay_platform}->gateway_list->{$Model->gateway}->encryption_list->{$Model->sign_type}; ?></td>
                        <td><a href="javascript:;" data-value="{{ Model.pay_config['encryption_key'] }}" data-field="encryption_key" data-title="微信<?php echo $this->config->payment_platform_list->{$Model->pay_platform}->gateway_list->{$Model->gateway}->encryption_list->{$Model->sign_type}; ?>" data-toggle="modal" data-target="#encryptionDisplayModal">查看</a> </td>
                    </tr>
                    <tr>
                        <td>CA证书</td>
                        <td><a href="javascript:;" data-value="{{ Model.pay_config['rootca'] }}" data-field="rootca" data-title="CA证书" data-toggle="modal" data-target="#encryptionDisplayModal">查看CA证书</a> </td>
                    </tr>
                    <tr>
                        <td>商户证书</td>
                        <td><a href="javascript:;" data-value="{{ Model.pay_config['merchant_cert'] }}" data-field="merchant_cert" data-title="商户证书公钥" data-toggle="modal" data-target="#encryptionDisplayModal">查看商户证书公钥</a> </td>
                    </tr>
                    <tr>
                        <td>商户证书密钥</td>
                        <td><a href="javascript:;" data-value="{{ Model.pay_config['merchant_cert_key'] }}" data-field="merchant_cert_key" data-title="商户证书私钥" data-toggle="modal" data-target="#encryptionDisplayModal">查看商户证书私钥</a> </td>
                    </tr>
                {% elseif Model.pay_platform == 'alipay' %}
                    {% if Model.gateway == 'wireless' or Model.gateway == 'partner' %}
                        <tr>
                            <td>支付宝账号</td>
                            <td>{{ Model.pay_config['alipay_account'] }}</td>
                        </tr>
                        <tr>
                            <td>合作伙伴身份（PID）</td>
                            <td>{{ Model.pay_config['partner'] }}</td>
                        </tr>
                        {% if Model.sign_type == 'MD5' %}
                        <tr>
                            <td><?php echo $this->config->payment_platform_list->{$Model->pay_platform}->gateway_list->{$Model->gateway}->encryption_list->{$Model->sign_type}; ?></td>
                            <td> <a href="javascript:;" data-value="{{ Model.pay_config['encryption_key'] }}"  data-field="encryption_key" data-title="微信<?php echo $this->config->payment_platform_list->{$Model->pay_platform}->gateway_list->{$Model->gateway}->encryption_list->{$Model->sign_type}; ?>" data-toggle="modal" data-target="#encryptionDisplayModal">查看</a> </td>
                        </tr>
                        {% else %}
                            <tr>
                                <td><?php echo $this->config->payment_platform_list->{$Model->pay_platform}->gateway_list->{$Model->gateway}->encryption_list->{$Model->sign_type}; ?></td>
                                <td>
                                    <a href="javascript:;" data-value="{{ Model.pay_config['alipay_private_cert'] }}"  data-field="alipay_private_cert" data-title="商户公钥" data-toggle="modal" data-target="#encryptionDisplayModal">查看商户公钥</a> |
                                    <a href="javascript:;" data-value="{{ Model.pay_config['alipay_public_cert'] }}" data-field="alipay_public_cert" data-title="支付宝公钥" data-toggle="modal" data-target="#encryptionDisplayModal">查看支付宝公钥</a>
                                </td>
                            </tr>
                        {% endif %}
                    {% elseif Model.gateway == 'openapp' %}
                        <tr>
                            <td>支付宝账号</td>
                            <td>{{ Model.pay_config['alipay_account'] }}</td>
                        </tr>
                        <tr>
                            <td>应用ID（APPID）</td>
                            <td>{{ Model.pay_config['app_id'] }}</td>
                        </tr>
                        {% if Model.sign_type == 'DES' %}
                            <tr>
                                <td><?php echo $this->config->payment_platform_list->{$Model->pay_platform}->gateway_list->{$Model->gateway}->encryption_list->{$Model->sign_type}; ?></td>
                                <td>  <a href="javascript:;" data-value="{{ Model.pay_config['encryption_key'] }}"  data-field="encryption_key" data-title="微信<?php echo $this->config->payment_platform_list->{$Model->pay_platform}->gateway_list->{$Model->gateway}->encryption_list->{$Model->sign_type}; ?>" data-toggle="modal" data-target="#encryptionDisplayModal">查看</a>  </td>
                            </tr>
                        {% else %}
                            <tr>
                                <td><?php echo $this->config->payment_platform_list->{$Model->pay_platform}->gateway_list->{$Model->gateway}->encryption_list->{$Model->sign_type}; ?></td>
                                <td>
                                    <a href="javascript:;" data-value="{{ Model.pay_config['alipay_private_cert'] }}"  data-field="alipay_private_cert" data-title="商户公钥" data-toggle="modal" data-target="#encryptionDisplayModal">查看商户公钥</a> |
                                    <a href="javascript:;" data-value="{{ Model.pay_config['alipay_public_cert'] }}" data-field="alipay_public_cert" data-title="支付宝公钥" data-toggle="modal" data-target="#encryptionDisplayModal">查看支付宝公钥</a>
                                </td>
                            </tr>
                        {% endif %}
                    {% endif %}
                {% elseif Model.pay_platform == 'alipay_global' %}

                {% endif %}
                </tbody>
            </table>
            <p></p>
        </form>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="encryptionDisplayModal" tabindex="-1" role="dialog" aria-labelledby="encryptionDisplayModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="encryptionDisplayModalTitle"></h4>
                </div>
                <div class="modal-body">
                    <div id="encryptionDisplayModalView">
                        <pre id="encryptionDisplayModalBody" style="background-color: white;font-size: 14px;border: none;"></pre><a href="javascript:editEncryption();">修改密钥</a>
                    </div>
                    <div id="encryptionDisplayModalForm" style="display: none;">
                        <form method="post" id="encryptionDisplayModalForm" action="{{ url('home/editEncryption') }}">
                            <input type="hidden" name="pay_id" value="{{ Model.pay_id }}">
                            <input type="hidden" name="field" value="">
                            <pre style="background-color: white;font-size: 14px;border: none;padding: 0">
                                <textarea name="encryption" class="form-control" style="height: 320px;resize: none;margin-bottom: 15px;"></textarea>
                            </pre>

                            <button type="submit" class="btn btn-primary-light btn-sm" data-loading-text="保存中...">保存</button>
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="payInfoEditModal" tabindex="-1" role="dialog" aria-labelledby="payInfoEditModal">
        <div class="modal-dialog" role="document">
            <form method="post" id="payInfoEditModalForm" action="{{ url('home/editPay') }}"  class="form-horizontal">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="payInfoEditModalTitle">编辑支付信息</h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" name="pay_id" value="{{ Model.pay_id }}">
                    <div class="form-group">
                        <label for="app_id" class="col-sm-2 control-label">支付名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="pay_name" name="pay_name" placeholder="支付名称" value="{{ Model.pay_name }}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">启用状态</label>
                        <div class="col-sm-10">
                            <div class="radio_box">
                                <label for="payment_state1" class="enable{{ Model.pay_status =='y' ? ' selected':'' }}">启用</label>
                                <label for="payment_state2" class="disable{{ Model.pay_status =='n' ? ' selected':'' }}">禁用</label>
                                <input type="radio" value="y" name="pay_status" id="payment_state1" {{ Model.pay_status =='y' ? 'checked="checked"':'' }}>
                                <input type="radio" value="n" name="pay_status" id="payment_state2" {{ Model.pay_status =='n' ? 'checked="checked"':'' }}>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="app_id" class="col-sm-2 control-label">支付简介</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" id="remark" name="remark" maxlength="1000" placeholder="支付简介" style="height: 120px;resize: none;">{{ Model.remark }}</textarea>

                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary-light btn-sm" data-loading-text="保存中...">保存</button>
                </div>
            </div>
            </form>
        </div>
    </div>
{% endblock %}
{% block footer %}
<script type="text/javascript">
    $(function () {
       $("#encryptionDisplayModal").on('show.bs.modal',function (e) {
           $("#encryptionDisplayModalTitle").text($(e.relatedTarget).attr('data-title'));
           $("#encryptionDisplayModalView").show();
           $("#encryptionDisplayModalBody").text($(e.relatedTarget).attr('data-value'));
           $("#encryptionDisplayModalForm").hide().find("textarea").text($(e.relatedTarget).attr('data-value'));
           $("#encryptionDisplayModalForm>input[name='field']").val($(e.relatedTarget).attr('data-field'));
       }) ;
    });

    /**
     * 编辑密钥
     */
    function editEncryption() {
        $("#encryptionDisplayModalView").hide();
        $("#encryptionDisplayModalForm").show();
    }

    $("#encryptionDisplayModalForm").ajaxForm({
        type : "POST",
        dataType :"json",
        resetForm: true,
        beforeSubmit : function () {
            $("#encryptionDisplayModalForm").find("button[type='submit']").button('loading');
        },
        success : function ($res) {
            var field = $("#encryptionDisplayModalForm>input[name='field']").val();if($res.errCode === 0 || $res.errCode === '0'){
                $("#encryptionDisplayModal").modal('hide');
                $("a[data-field='"+field+"']").attr('data-value', $("#encryptionDisplayModalForm").find('textarea').val());
                layer.msg('保存成功');
            }else{
                layer.msg('保存失败')
            }
            $("#encryptionDisplayModalForm").find("button[type='submit']").button('reset');
        },
        error : function () {
            layer.msg('保存失败');
            $(this).find("button[type='submit']").button('reset');
            $("#encryptionDisplayModalView").show();
            $("#encryptionDisplayModalForm").hide();
        }
    });

    $("#payInfoEditModalForm").ajaxForm({
        type : "POST",
        dataType :"json",
        beforeSubmit : function () {
            $("#payInfoEditModalForm").find("button[type='submit']").button('loading');
        },
        success : function ($res) {
            $("#payInfoEditModalForm").find("button[type='submit']").button('reset');
            if($res.errCode === 0 || $res.errCode === '0'){
                $("#payInfoEditModal").modal('hide');
                $("#pay_name_text").text($res.pay_name);
                $("#pay_status_text").text($res.pay_status);
                $("#remark_text").text($res.remark);
                layer.msg('保存成功');
            }else{
                layer.msg('保存失败');
            }

       },
        error : function () {
            $("#payInfoEditModalForm").find("button[type='submit']").button('reset');
            layer.msg('保存失败');
        }
    });
</script>
{% endblock %}